package com.lhy.tool.database.converter.common;

import com.lhy.tool.autoconfigation.GeneratorProperties;
import com.lhy.tool.database.DateType;
import com.lhy.tool.database.DbColumnType;
import com.lhy.tool.util.SpringUtil;

import java.util.function.Function;

public abstract class AbstractDbDateTimeConverter implements Function<String, DbColumnType> {

    private DateType getConfigDateType() {
        GeneratorProperties generatorProperties = SpringUtil.getBean(GeneratorProperties.class);
        return generatorProperties.getGlobalConfig().getDateType();
    }

    protected abstract DbColumnType convert(DateType configDateType);

    @Override
    public DbColumnType apply(String s) {
        DateType configDateType = getConfigDateType();
        return convert(configDateType);
    }

}
